var __Browser={};
var domTimer;
var http_request;
var ajaxUrl = "ajaxInterface.php?";


(function getBrowserAgent(){
	var agent = navigator.userAgent;
	__Browser.IE = !!agent.match(/MSIE/);
	__Browser.FF = agent.match(/Mozilla/i)&&!agent.match(/compatible|WebKit/i);
	__Browser.Opera = !!agent.match(/Opera/i);
	__Browser.Safari = !!agent.match(/Mac|Safari/i);
})();


function $addEvent(obj , evt , fn){
	if(__Browser.IE){
		obj.attachEvent("on"+evt , fn);
	}
	else{
		obj.addEventListener(evt , fn ,false);
	}
}

function $(id){
	if(!id) return false;
	return document.getElementById(id);
}

function $t(id){
	return document.getElementsByTagName(id);
}

function __domready(){
	if(__Browser.FF){
		$addEvent(document , "DOMContentLoaded" , __init)
	}
	if(__Browser.IE){
		domTimer = setInterval(function(){
			try{
				document.body.doScroll('right');
				clearInterval(domTimer)
				__init();
			}catch(e){};
		});
	}
}

function getSrcEl(e){
	var evt = window.event || e;
	var src = evt.target || evt.srcElement;
	return src;
}

function createXMLHTTPObject(){
	var XMLHttpFactories = [
		function() {return new XMLHttpRequest();},
		function() {return new ActiveXObject('Msxml2.XMLHTTP');},
		function() {return new ActiveXObject('Msxml3.XMLHTTP');},
		function() {return new ActiveXObject('Microsoft.XMLHTTP');}
	];
	var xmlhttp = false;
	for(var i=0;i<XMLHttpFactories.length;i++){
		try{
			xmlhttp = XMLHttpFactories[i]();
		}
		catch(e){
			continue;
		}
	}
	return xmlhttp;
}

function makeAjaxRequest(url , data , sys , callback){
	http_request = createXMLHTTPObject();
	 if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
     }

	http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			callback();
		 }
	  }
	}
	http_request.open('POST', url, sys);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	if(data) { http_request.setRequestHeader("Content-length", data.length); }
	http_request.setRequestHeader("Connection", "close");
	http_request.send(data);
}


Function.prototype.bind = function(obj){
	var f = this;
	var a = [].slice.call(arguments, 1);
	return function(){
		return f.apply(obj,a.concat([].slice.call(arguments, 0)));
	};
};

Function.prototype.pass = function(){
	var a = [].slice.call(arguments, 0);
	a.unshift(null);
	return this.bind.apply(this, a);
};

String.prototype.trim = function(){
	return this.replace(/^\s+/,"").replace(/\s+$/,"");
}

